package com.avic.rong.activity.mine;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.webkit.JavascriptInterface;
import android.webkit.WebSettings;

import com.avic.rong.BaseActivity;
import com.avic.rong.R;
import com.avic.rong.utils.SharedPreferencesUtil;
import com.orhanobut.logger.Logger;

import java.net.URLEncoder;

import butterknife.BindView;
import wendu.dsbridge.DWebView;

//反馈意见
public class SuggestionActivity extends BaseActivity {


    @BindView(R.id.webview)
    DWebView webview;


    @Override
    protected int getContentViewId() {
        return R.layout.activity_suggestion;
    }

    @Override
    protected void initView() {
        tvTitle.setText("反馈建议");
        ivRight.setBackgroundResource(R.mipmap.slh);

        webview.addJavascriptObject(this, null);

        initWebview();
        webview.getSettings().setBlockNetworkImage(false);//解决图片不显示
        webview.loadUrl("http://nm.rongrong.huazhi365.com/help/reportDetail");

    }


    //同步获取编码token
    @JavascriptInterface
    public String getLoginUserEncode(Object msg) {
        String login_token = "";
        if (SharedPreferencesUtil.isLogin()) {
            try {
                login_token = URLEncoder.encode(SharedPreferencesUtil.getLoginToken(), "UTF-8");
            } catch (Exception e) {
                Logger.i(e.getMessage());
            }
        }
        return login_token;
    }

    private void initWebview() {
        WebSettings setting = webview.getSettings();
        setting.setJavaScriptEnabled(true);//支持Js
        setting.setCacheMode(WebSettings.LOAD_DEFAULT);//缓存模式
        //是否支持画面缩放，默认不支持
        setting.setBuiltInZoomControls(true);
        setting.setSupportZoom(true);
        //是否显示缩放图标，默认显示
        setting.setDisplayZoomControls(false);
        //设置网页内容自适应屏幕大小
        setting.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING);//注意网上例程很多的是.SINGLE_COLUMN，但调试时发现移动版网站会错位，所以改成
        //SINGLE_COLUMN

        setting.setUseWideViewPort(true);
        setting.setLoadWithOverviewMode(true);

    }
    @Override
    protected void addListener() {

        ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    public static Intent queryIntent(Context context) {
        Intent intent = new Intent(context, SuggestionActivity.class);
        return intent;
    }

}
